package org.zuul;
//
//import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.DefaultRateLimitKeyGenerator;
//import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.RateLimitKeyGenerator;
//import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.properties.RateLimitProperties;
import org.springframework.cloud.netflix.zuul.filters.Route;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.http.HttpServletRequest;

@Configuration
public class Config {

	/*自定义限流
	 * 比如有一个请求是http://localhost:8765/api-a//hello2?name=kevin，
	 * 对相同的name值进行限流。我们设置了1分钟内，限流10次，
	 * 那么如果1分钟内，name是kevin的请求超过10次，就会发生限流。
	 * */
//	@Bean
//	public RateLimitKeyGenerator rateLimitKeyGenerator(final RateLimitProperties properties){
//		return new DefaultRateLimitKeyGenerator(properties){
//			@Override
//			public String key(HttpServletRequest request, Route route, RateLimitProperties.Policy policy) {
//				String name = request.getParameter("name");
////                return super.key(request, route, policy);
//				return super.key(request, route, policy)+":"+name;
//			}
//		};
//	}
}